#include <iostream>
#include <unordered_map>
#include "test.h"
using namespace std;
class Person{
 public:
    Person(int name_, int age_):name(name_),age(age_){}
    int name;
    int age;
};
// A unary function object type that takes an object of type key type as argument and returns a unique value of type size_t based on it.
// This can either be a class implementing a function call operator or a pointer to a function (see constructor for an example).
// This defaults to hash<Key>, which returns a hash value with a probability of collision approaching 1.0/std::numeric_limits<size_t>::max().
// The unordered_map object uses the hash values returned by this function to organize its elements internally, speeding up the process of locating individual elements.
// Aliased as member type unordered_map::hasher.
class HashOfPerson{
 public:
    int operator() (const Person & person) const {
        return person.name + person.age;
    }
};

class EqualOfPerson{
 public:
    bool operator() (const Person &lhs, const Person& rhs) const {
        return (lhs.name == rhs.name) && (lhs.age == rhs.age);
    }
};
typedef std::unordered_map<Person, std::string, HashOfPerson, EqualOfPerson>  PersonPool;


class test_unordered_map :public TestBase{
 public:
    test_unordered_map() : TEST {}
    void do_test() {
        PersonPool person_pool;
        person_pool[Person(1, 2)] = "liuping";
        person_pool[Person(2, 1)] = "xiongxiao";
        std::cout<<person_pool[Person(1, 2)];
    }
};

